﻿@model Inovout.Kuajing.Models.ShippingTemplate
@{
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}
@section styles {

    <style>
        .form form {
            margin: 20em auto;
        }

        .logisticForm {
            margin-top: 3em;
        }

            .logisticForm select {
                max-width: 280px;
            }

            .logisticForm radio label {
                padding-left: 30px;
            }



        .default {
            margin: 20px 20px 20px 20px;
        }

            .default input, #tb_condition input {
                width: 80px;
            }

        .custom {
            margin-left: 10px;
            margin-right: 10px;
        }

            .custom input {
                width: 50px;
            }

        a.area {
            margin-left: 300px;
            margin-right: 0px;
        }

        div.express, div.mail, div.ems {
            display: none;
            border: 1px solid #23527C;
        }

        div.error {
            padding-left: 2px;
            padding-bottom: 2px;
            font-weight: bold;
            color: #EA5200;
        }

        .elementvisable {
            display:none;
        }

        #tb_condition select {
          width:80px;
          border:1px solid gray;
        }

        a.front,a.after{
          font-size:25px;
          margin-left:20px;
          color:black;
          font-weight:400;
        }
    </style>
}

@section scriptsHead {
   
    <script type="text/javascript">

        var page = {};
        page.deleRow = function (obj) {
            var trs = $(obj).parents("tbody").find("tr");
            if (trs.length == 1) {
                $(obj).parents("table").remove();
            } else {
                $(obj).parents("tr").remove();
            }

        }

        page.InitData = function () {
            var tableHeader = "<table class=\"table table-bordered\" id=\"tb_piece\"><thead><tr><td>运送到</td><td>首件(件)</td><td>首费(元)</td><td>续件(件)</td><td>续费(元)</td>" +
                                    "<td>操作</td></tr></thead><tbody></tbody></table>";
            var defaultPiece = "<label>默认运费:<input type=\"text\" />件内，<input type=\"text\" />元，每增加<input type=\"text\" />件，增加运费<input type=\"text\" />元</label>";

            var express = $("#express");
            express.children("div.default").empty();
            express.children("div.default").append(defaultPiece);
            express.children("div.custom").empty();

            var ems = $("#ems");
            ems.children("div.default").empty();
            ems.children("div.default").append(defaultPiece);
            ems.children("div.custom").empty();

            var mail = $("#mail");
            mail.children("div.default").empty();
            mail.children("div.default").append(defaultPiece);
            mail.children("div.custom").empty();
        }

        page.SelectData = function ($select) {
            var value = $select.find("option:selected").val();
            if (value == 1) {
                $select.parents("tr").find("div.condition1").css("display", "block");
                $select.parents("tr").find("div.condition2").css("display", "none");
                $select.parents("tr").find("div.condition3").css("display", "none");
            }

            if (value == 2) {
                $select.parents("tr").find("div.condition1").css("display", "none");
                $select.parents("tr").find("div.condition2").css("display", "block");
                $select.parents("tr").find("div.condition3").css("display", "none");
            }

            if (value == 3) {
                $select.parents("tr").find("div.condition1").css("display", "none");
                $select.parents("tr").find("div.condition2").css("display", "none");
                $select.parents("tr").find("div.condition3").css("display", "block");
            }
        }


        /* 全选和全不选*/
        var exressAreas = [];
        var exressAreaNames = [];
        var currenrowexressAreas = [];
        var currenrowAreaNames = [];
        page.CKRegionHandle = function (object) {

            exressAreas.pop($(object).pop("id"));
            exressAreaNames.pop($(object).next().text())
            var provice = $(object).parents("div.region").parent().find("div.provice").find("input");
            var selected = $(object).is(':checked');
            if (selected) {
                provice.each(function (index, item) {
                    $(item).prop("checked", true);
                })
            } else {
                provice.each(function (index, item) {
                    $(item).removeAttr("checked");
                })
            }
        }

        page.CKProviceHandle = function (object) {

            exressAreas.pop($(object).pop("id"));
            exressAreaNames.pop($(object).next().text())
        }


        page.editArea = function (object, diaogId) {
            $("#" + diaogId).modal('show');
        }

        $(document).ready(function () {
            //设置默认为中国

            $("#GoodCountry").val("142");

            var is_seller = false;
            var tableHeader = "";

            var defaultPieceExpreess = "<label>默认运费:<input type=\"text\"  class=\"required number\" name=\"piecefree\" />件内，<input type=\"text\" class=\"required number\" name=\"piecefree1\"  />元，每增加<input type=\"text\" class=\"required number\" name=\"piecefree2\"  />件，增加运费<input type=\"text\" class=\"required number\" name=\"piecefree3\"  />元</label><div id='defaultError1'></div>";
            var defaultPieceEms = "<label>默认运费:<input type=\"text\"  class=\"required number\" name=\"piecefree4\" />件内，<input type=\"text\" class=\"required number\" name=\"piecefree5\"  />元，每增加<input type=\"text\" class=\"required number\" name=\"piecefree6\"  />件，增加运费<input type=\"text\" class=\"required number\" name=\"piecefree7\"  />元</label><div id='defaultError2'></div>";
            var defaultPieceMail = "<label>默认运费:<input type=\"text\"  class=\"required number\" name=\"piecefree8\" />件内，<input type=\"text\" class=\"required number\" name=\"piecefree9\"  />元，每增加<input type=\"text\" class=\"required number\" name=\"piecefree10\"  />件，增加运费<input type=\"text\" class=\"required number\" name=\"piecefree11\"  />元</label><div id='defaultError3'></div>";

            var defaultWeightExpress = "<label>默认运费:<input type=\"text\" class=\"required number\" name=\"weightfree\"  />kg内，<input type=\"text\" class=\"required number\" name=\"weightfree1\"  />元，每增加<input type=\"text\" class=\"required number\" name=\"weightfree2\" />kg，增加运费<input type=\"text\" class=\"required number\" name=\"weightfree3\" />元</label>";
            var defaultWeightEms = "<label>默认运费:<input type=\"text\" class=\"required number\" name=\"weightfree4\"  />kg内，<input type=\"text\" class=\"required number\" name=\"weightfree5\"  />元，每增加<input type=\"text\" class=\"required number\" name=\"weightfree6\" />kg，增加运费<input type=\"text\" class=\"required number\" name=\"weightfree7\" />元</label>";
            var defaultWeightMail = "<label>默认运费:<input type=\"text\" class=\"required number\" name=\"weightfree8\"  />kg内，<input type=\"text\" class=\"required number\" name=\"weightfree9\"  />元，每增加<input type=\"text\" class=\"required number\" name=\"weightfree10\" />kg，增加运费<input type=\"text\" class=\"required number\" name=\"weightfree11\" />元</label>";

           var defaultVolumeExpress = "<label>默认运费:<input type=\"text\" class=\"required number\" name=\"volumefree\" />m内，<input type=\"text\" class=\"required number\" name=\"volumefree1\" />元，每增加<input type=\"text\" class=\"required number\" name=\"volumefree2\" />m，增加运费<input type=\"text\" class=\"required number\" name=\"volumefree3\" />元</label>";
           var defaultVolumeEms = "<label>默认运费:<input type=\"text\" class=\"required number\" name=\"volumefree4\" />m内，<input type=\"text\" class=\"required number\" name=\"volumefree5\" />元，每增加<input type=\"text\" class=\"required number\" name=\"volumefree6\" />m，增加运费<input type=\"text\" class=\"required number\" name=\"volumefree7\" />元</label>";
           var defaultVolumeMail = "<label>默认运费:<input type=\"text\" class=\"required number\" name=\"volumefree8\" />m内，<input type=\"text\" class=\"required number\" name=\"volumefree9\" />元，每增加<input type=\"text\" class=\"required number\" name=\"volumefree10\" />m，增加运费<input type=\"text\" class=\"required number\" name=\"volumefree11\" />元</label>";


            page.InitData();


            /* 是否包邮*/
            $("#rdseller").on("click", function () {
                var express = $("#express");
                express.children("div.default").empty();
                express.children("div.custom").empty();
                $("#express").hide();

                var ems = $("#ems");
                ems.children("div.default").empty();
                ems.children("div.custom").empty();
                $("#ems").hide();

                var mail = $("#mail");
                mail.children("div.default").empty();
                mail.children("div.custom").empty();
                $("#mail").hide();
                is_seller = true;

                $("div.freeshipping").hide();


                $("#ckExpress").removeAttr("checked");
                $("#ckEMS").removeAttr("checked");
                $("#ckOrgMail").removeAttr("checked");

            })

            $("#rdcustom").on("click", function () {
                var express = $("#express");
                express.children("div.default").empty();
                express.children("div.custom").empty();
                $("#express").hide();

                var ems = $("#ems");
                ems.children("div.default").empty();
                ems.children("div.custom").empty();
                $("#ems").hide();

                var mail = $("#mail");
                mail.children("div.default").empty();
                mail.children("div.custom").empty();
                $("#mail").hide();
                is_seller = false;
                $("div.freeshipping").show();
                $("#ckExpress").removeAttr("checked");
                $("#ckEMS").removeAttr("checked");
                $("#ckOrgMail").removeAttr("checked");

                $("#PriceWayPiece").click();
            })


            /* 计价方式*/
            $("#PriceWayPiece").on("click", function () {
                tableHeader = "<table class=\"table table-bordered\" id=\"tb_piece\"><thead><tr><td>运送到</td><td>首件(件)</td><td>首费(元)</td><td>续件(件)</td><td>续费(元)</td>" +
                                    "<td>操作</td></tr></thead><tbody></tbody></table>";

                var express = $("#express");
                express.children("div.default").empty();
                express.children("div.default").append(defaultPieceExpreess);
                express.children("div.custom").empty();

                var ems = $("#ems");
                ems.children("div.default").empty();
                ems.children("div.default").append(defaultPieceEms);
                ems.children("div.custom").empty();

                var mail = $("#mail");
                mail.children("div.default").empty();
                mail.children("div.default").append(defaultPieceMail);
                mail.children("div.custom").empty();

                //包邮条件中的计价方式
                $(".freeshipprice").each(function (index, item) {
                    $(item).empty();
                    $(item).append("<option value=\"1\" selected='true'>件数</option>");
                    $(item).append("<option value=\"2\">金额</option>");
                    $(item).append("<option value=\"3\">件数+金额</option>");
                    page.SelectData($(item));
                })

                $(".condition1").each(function (index, item) {
                    $(item).empty();
                    $(item).append("满<input type=\"text\" class=\"required number\" name=\"piece"+index+"\" style=\"width: 40px;\" />件包邮");
                })

                $(".condition2").each(function (index, item) {
                    $(item).empty();
                    $(item).append("满<input type=\"text\" class=\"required number\" name=\"yuan" + index + "\" style=\"width: 40px;\" />元包邮");
                })

                $(".condition3").each(function (index, item) {
                    $(item).empty();
                    $(item).append("满<input type=\"text\" class=\"required number\" name=\"pieceful" + index + "\" style=\"width: 40px;\" />件，<input type=\"text\"  name=\"yuanful" + index + "\" style=\"width: 40px;\" />元以上包邮");
                })


            })

            $("#PriceWayWeight").on("click", function () {
                tableHeader = "<table class=\"table table-bordered\" id=\"tb_weight\"><thead><tr><td>运送到</td><td>首重(kg)</td><td>首费(元)</td><td>续重(kg)</td><td>续费(元)</td>" +
                                    "<td>操作</td></tr></thead><tbody></tbody></table>";
                var express = $("#express");
                express.children("div.default").empty();
                express.children("div.default").append(defaultWeightExpress);
                express.children("div.custom").empty();

                var ems = $("#ems");
                ems.children("div.default").empty();
                ems.children("div.default").append(defaultWeightEms);
                ems.children("div.custom").empty();

                var mail = $("#mail");
                mail.children("div.default").empty();
                mail.children("div.default").append(defaultWeightMail);
                mail.children("div.custom").empty();

                //包邮条件中的计价方式
                $(".freeshipprice").each(function (index, item) {
                    $(item).empty();
                    $(item).append("<option value=\"1\" selected='true'>重量</option>");
                    $(item).append("<option value=\"2\">金额</option>");
                    $(item).append("<option value=\"3\">重量+金额</option>");
                    page.SelectData($(item));
                })

                $(".condition1").each(function (index, item) {
                    $(item).empty();
                    $(item).append("满<input type=\"text\" class=\"required number\" name=\"weight" + index + "\" style=\"width: 40px;\" />kg包邮");
                })

                $(".condition2").each(function (index, item) {
                    $(item).empty();
                    $(item).append("满<input type=\"text\" class=\"required number\" name=\"weightyuan" + index + "\" style=\"width: 40px;\" />元包邮");
                })

                $(".condition3").each(function (index, item) {
                    $(item).empty();
                    $(item).append("满<input type=\"text\" class=\"required number\" name=\"weightful" + index + "\" style=\"width: 40px;\" />kg，<input type=\"text\" class=\"required number\" name=\"weightyuanful" + index + "\" style=\"width: 40px;\" />元以上包邮");
                })

            })

            $("#PriceWayVolume").on("click", function () {
                tableHeader = "<table class=\"table table-bordered\" id=\"tb_volumn\"><thead><tr><td>运送到</td><td>首体积(m)</td><td>首费(元)</td><td>续体积(m)</td><td>续费(元)</td>" +
                                   "<td>操作</td></tr></thead><tbody></tbody></table>";
                var express = $("#express");
                express.children("div.default").empty();
                express.children("div.default").append(defaultVolumeExpress);
                express.children("div.custom").empty();

                var ems = $("#ems");
                ems.children("div.default").empty();
                ems.children("div.default").append(defaultVolumeEms);
                ems.children("div.custom").empty();

                var mail = $("#mail");
                mail.children("div.default").empty();
                mail.children("div.default").append(defaultVolumeMail);
                mail.children("div.custom").empty();

                //包邮条件中的计价方式
                $(".freeshipprice").each(function (index, item) {
                    $(item).empty();
                    $(item).append("<option value=\"1\" selected='true'>体积</option>");
                    $(item).append("<option value=\"2\">金额</option>");
                    $(item).append("<option value=\"3\">体积+金额</option>");
                    page.SelectData($(item));
                })
                $(".condition1").each(function (index, item) {
                    $(item).empty();
                    $(item).append("满<input type=\"text\" class=\"required number\" name=\"volume" + index + "\" style=\"width: 40px;\" />体积包邮");
                })

                $(".condition2").each(function (index, item) {
                    $(item).empty();
                    $(item).append("满<input type=\"text\" class=\"required number\" name=\"volumeyuan" + index + "\"  style=\"width: 40px;\" />元包邮");
                })

                $(".condition3").each(function (index, item) {
                    $(item).empty();
                    $(item).append("满<input type=\"text\" class=\"required number\" name=\"volumful" + index + "\" style=\"width: 40px;\" />体积，<input type=\"text\" class=\"required number\" name=\"volumeyuanful" + index + "\" style=\"width: 40px;\" />元以上包邮");
                })
            })


            /* 运送方式*/
            $("#ckExpress").on("click", function () {
                var express = $("#express");
                if (is_seller) {
                    express.hide();
                } else {
                    express.toggle();
                }
                //添加option <option value="1" selected="true">快件</option>
                var checked = $(this).is(":checked");//.prop('checked')1.6 以上
                var text = $(this).prop("data-method");
                var value = $(this).prop("value");
                if (checked) {
                    //添加在条件包邮中的运送方式
                    $(".freeshiptransfer").each(function (index, item) {
                        var is_add = false;
                        $(item).find("option").each(function (i, option) {
                            if ($(option).attr("value") == value) {
                                is_add = true;
                            }
                        })

                        if (!is_add) {
                            $(item).append("<option value=\"" + value + "\" selected=\"true\">快递</option> ")
                        }
                    })
                } else {
                    $(".freeshiptransfer").each(function (index, item) {
                        $(item).find("option").each(function (i, option) {
                            if ($(option).attr("value") == value) {
                                $(option).remove();
                            }
                        })
                    })
                }




            })

            $("#ckEMS").on("click", function () {
                var ems = $("#ems");
                if (is_seller) {
                    ems.hide();
                } else {
                    ems.toggle();
                }

                //添加option <option value="2" selected="true">EMS</option>
                var checked = $(this).is(":checked");//.prop('checked')1.6 以上
                var text = $(this).prop("data-method");
                var value = $(this).prop("value");
                if (checked) {
                    //添加在条件包邮中的运送方式
                    $(".freeshiptransfer").each(function (index, item) {
                        var is_add = false;
                        $(item).find("option").each(function (i, option) {
                            if ($(option).attr("value") == value) {
                                is_add = true;
                            }
                        })

                        if (!is_add) {
                            $(item).append("<option value=\"" + value + "\">EMS</option> ")
                        }
                    })
                } else {
                    $(".freeshiptransfer").each(function (index, item) {
                        $(item).find("option").each(function (i, option) {
                            if ($(option).attr("value") == value) {
                                $(option).remove();
                            }
                        })
                    })
                }
            })



            $("#ckOrgMail").on("click", function () {
                var mail = $("#mail");
                if (is_seller) {
                    mail.hide();
                } else {
                    mail.toggle();
                }

                //添加option <option value="3" selected="true">平邮</option>
                var checked = $(this).is(":checked");//.prop('checked')1.6 以上
                var text = $(this).prop("data-method");
                var value = $(this).prop("value");
                if (checked) {
                    //添加在条件包邮中的运送方式
                    $(".freeshiptransfer").each(function (index, item) {
                        var is_add = false;
                        $(item).find("option").each(function (i, option) {
                            if ($(option).attr("value") == value) {
                                is_add = true;
                            }
                        })

                        if (!is_add) {
                            $(item).append("<option value=\"" + value + "\">平邮</option> ")
                        }
                    })
                } else {
                    $(".freeshiptransfer").each(function (index, item) {
                        $(item).find("option").each(function (i, option) {
                            if ($(option).attr("value") == value) {
                                $(option).remove();
                            }
                        })
                    })
                }
            })

            /* 添加区域运送的计费方式*/
            var pieceArea = "<tr><td>未添加地区<input type=\"hidden\" /> <a class=\"area\" onclick=\"page.editArea(this,'expressSelect')\" >" +
                                   "编辑</a></td><td><input type=\"text\" /></td><td><input type=\"text\" /></td>" +
                                   "<td><input type=\"text\" /></td><td><input type=\"text\" /></td><td><a onclick=\"page.deleRow(this)\">删除</a></td></tr>";

            var weightArea = "<tr><td>未添加地区<input type=\"hidden\" /> <a class=\"area\" onclick=\"page.editArea(this,'emsSelect')\" >" +
                               "编辑</a></td><td><input type=\"text\" /></td><td><input type=\"text\" /></td>" +
                               "<td><input type=\"text\" /></td><td><input type=\"text\" /></td><td><a onclick=\"page.deleRow(this)\">删除</a></td></tr>";


            var mailArea = "<tr><td>未添加地区<input type=\"hidden\" /> <a class=\"area\" onclick=\"page.editArea(this,'mailSelect')\" >" +
                               "编辑</a></td><td><input type=\"text\" /></td><td><input type=\"text\" /></td>" +
                               "<td><input type=\"text\" /></td><td><input type=\"text\" /></td><td><a onclick=\"page.deleRow(this)\">删除</a></td></tr>";
            $("#addexpressFree").on("click", function () {

                var express = $("#express");
                var table = express.find("table");
                if (table.length == 0) {
                    table = $(tableHeader);
                    table.append(pieceArea);
                    express.children("div.custom").append(table);
                } else {
                    table.append(area);
                }

            })

            $("#addemsFree").on("click", function () {

                var ems = $("#ems");
                var table = ems.find("table");

                if (table.length == 0) {
                    table = $(tableHeader);
                    table.append(weightArea);
                    ems.children("div.custom").append(table);
                } else {
                    table.append(area);
                }

            })

            $("#addmaiFree").on("click", function () {

                var mail = $("#mail");
                var table = mail.find("table");
                if (table.length == 0) {
                    table = $(tableHeader);
                    table.append(mailArea);
                    mail.children("div.custom").append(table);
                } else {
                    table.append(area);
                }
            })

            /* 默认计价方式*/
            $("#PriceWayPiece").click();

            /* 选择地区*/
            $.ajax({
                type: "GET",
                url: '../../Files/Json/address.js',
                dataType: "json",
                success: function (data) {
                    $.each(data.region, function (index, content) {
                        var htmlRegion = "<div class=\"row\"><div class=\"col-md-2 region\">";
                        var ckRegion = " <label class=\"checkbox-inline\"><input  type=\"checkbox\" onclick=\"page.CKRegionHandle(this)\"  value=" + content.code + " /> <strong>" + content.name + "</strong></label>";
                        htmlRegion = htmlRegion + ckRegion
                        var htmlProvice = "</div><div class=\"col-md-10 provice\">";
                        $.each(content.provice, function (index, content) {
                            var ckProvice = "<label class=\"checkbox-inline\"><input  onclick=\"page.CKProviceHandle(this)\" type=\"checkbox\" value=" + content.code + " /> " + content.name + "</label>";
                            htmlProvice = htmlProvice + ckProvice;
                        })
                        htmlProvice = htmlProvice + "</div>"
                        htmlRegion = htmlRegion + htmlProvice;
                        htmlRegion = htmlRegion + "</div>";
                        $(".modal-body").append(htmlRegion);

                    })
                },
                complete: function (XMLHttpRequest, textStatus) {

                },
                erro: function (XMLHttpRequest, textStatus, errorThrown) {
                }

            })






            $("#tb_condition").find("a.after").each(function () {
                $(this).on("click", function () {
                    $(this).parents("tr").remove();
                })
            })


            $("#tb_condition").find("a.front").each(function () {
                $(this).on("click", function () {
                    page.addCondtion($(this));
                })

            })


            $("select.freeshipprice").each(function (index, item) {
                $(this).on("change", function () {
                    page.SelectData($(this));
                })

            })


            //是否显示包邮
            $("#tb_condition").hide();
            $("#ckcondition").on("click", function () {
                debugger;
                var selected = $(this).is(':checked');
                if (selected) {
                    $("#tb_condition").show();

                } else {
                   // $("#tb_condition tbody").children("tr").remove();
                    $("#tb_condition").hide();
                }

            })


            // 验证
            $("#logisticForm").validate({
                rules: {
                    Name: {
                        required: true,
                        minlength: 3
                    }
                },
                messages: {
                    Name: {
                        required: "请输入模板名称",
                        minlength: "最小长度不小于3"
                    }
                },
                errorElement: "div"
            })

            $("#btlogistics").on("click", function () {
                debugger;
                var freightInfos = [];
                var freeShippingInfos = [];
                //计价方式
                $("input[name='ShippingWay']").each(function (index, item) {
                    debugger
                    var freightInfo = {};
                    var checked = $(item).is(":checked");
                    if (checked) {
                        var value = $(item).prop("value");
                        freightInfo.ShippingWay = value;
                        var firstinput = $(item).parents("div.checkbox").next().find("div.default").find("input[type='text']").eq(0);
                        var secondinput = firstinput.next();
                        var thirdinput = secondinput.next();
                        var fourthinput = thirdinput.next();
                        freightInfo.FirstInMeasure = firstinput.val();
                        freightInfo.FirstMoney = secondinput.val();
                        freightInfo.RenewMeasure = thirdinput.val();
                        freightInfo.RenewMoney = fourthinput.val();
                        freightInfos.push(freightInfo);
                    }                   
                })
                debugger;

                //包邮条件
                if ($("#ckcondition").is(":checked")) {
                    $("#tb_condition tbody").find("tr").each(function (index, item) {
                        var freeShippingInfo = {};
                        debugger;
                        var shippingway = $(item).find("td").eq(2).find("select");
                        var value = shippingway.val();

                        if (value) {
                            freeShippingInfo.ShippingWay = value;
                        }

                        var priceway = $(item).find("td").eq(4).find("select");
                        value = priceway.val();
                        if (priceway) {

                            freeShippingInfo.PriceWay = value;
                        }

                        //var express = $(item).find("td").eq(4).find("div:not(:visible)")
                        var express = $(item).find("td").eq(4).find("div:visible")
                        express.find("input[type='text']").each(function (index, item) {
                            if (value == 1) {
                                if (index == 0) {
                                    freeShippingInfo.quality = $(item).val();
                                }
                            }

                            if (value == 2) {
                                if (index == 0) {
                                    freeShippingInfo.money = $(item).val();
                                }
                            }

                            if (value == 3) {
                                if (index == 0) {
                                    freeShippingInfo.quality = $(item).val();
                                }
                                if (index == 1) {
                                    freeShippingInfo.money = $(item).val();
                                }
                            }

                        })
                        debugger;
                        freeShippingInfos.push(freeShippingInfo);
                    })
                }
                $("#freight").val(JSON.stringify(freightInfos));
                $("#freeship").val(JSON.stringify(freeShippingInfos));
            })

        })



        page.cutCondtion = function (objet) {
            $(objet).parents("tr").remove();

        }

        page.addCondtion = function ($object) {
            var contion = $object.parents("tr");
            var cloneObject = contion.clone(true, true);
            cloneObject.find("select.freeshiptransfer").val(1);
            cloneObject.find("select.freeshipprice").val(1);
            page.SelectData(cloneObject.find("select.freeshipprice"));
            cloneObject.appendTo($("#tb_condition tbody"));
        }



    </script>

}

<div class="row">
    @using (Html.BeginForm("SaveShippingTemplate", "Logistics", FormMethod.Post, new { @class = "form-horizontal logisticForm", @id = "logisticForm" }))
    {
        @Html.ValidationSummary(true)
        <div class="form-group">
            @Html.LabelFor(model => model.Name, "模板名称", new { @for = "Name", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(mode => mode.Name, new { @placeholder = "南京三宝", @class = "form-control" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.GoodCountry, "宝贝地址", new { @for = "GoodCountry", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.GoodCountry, (SelectList)ViewData["Countries"], new { @class = "form-control" })
                @Html.HiddenFor(model => model.GoodCountry)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.DeliveryTime, "发货时间", new { @for = "DeliveryTime", @class = "col-md-2 control-label" })
            <div class="col-md-10 ">
                @Html.DropDownListFor(model => model.DeliveryTime, (SelectList)ViewData["DeliveryTime"], new { @class = "form-control" })
                @Html.HiddenFor(model => model.DeliveryTime)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Is_Shipping, "是否包邮", new { @for = "Is_Shipping", @class = "col-md-2 control-label" })
            <div class="col-md-10 radio">
                <label>
                    @Html.RadioButtonFor(model => model.Is_Shipping, "0", new { @checked = "checked", @id = "rdcustom" })自定义邮费
                </label>
                <label>
                    @Html.RadioButtonFor(model => model.Is_Shipping, "1", new { @id = "rdseller" })卖家承担邮费
                </label>
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Is_Shipping, "计价方式", new { @for = "Is_Shipping", @class = "col-md-2 control-label" })
            <div class="col-md-10 radio">
                <label>
                    @Html.RadioButtonFor(model => model.PriceWay, "0", new { @id = "PriceWayPiece", @checked = "checked" })按件数
                </label>
                <label>
                    @Html.RadioButtonFor(model => model.PriceWay, "1", new { @id = "PriceWayWeight" })按重量
                </label>
                <label>
                    @Html.RadioButtonFor(model => model.PriceWay, "2", new { @id = "PriceWayVolume" }) 按体积
                </label>
                <input  type="hidden" name='Consigner.Id' value="@ViewBag.ConsignerId" />
            </div>
        </div>
        
      
        <div class="form-group">
            @Html.LabelFor(model => model.Is_Shipping, "运送方式", new { @for = "Is_Shipping", @class = "col-md-2 control-label" })
            <div class="col-md-10 checkbox">
                <p>除指定地区外，其余地区的运费采用“默认运费”</p>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="ShippingWay" data-method="快递" value="1" id="ckExpress">
                        快递
                    </label>
                </div>
                <div class="express" id="express">
                    <div class="default">
                    </div>
                    <div class="custom">
                    </div>
                    <div><a id="addexpressFree" class="elementvisable">为指定地区城市设置运费</a></div>
                </div>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="ShippingWay" data-method="EMS" value="2" id="ckEMS">
                        EMS
                    </label>
                </div>
                <div class="ems" id="ems">
                    <div class="default">
                    </div>
                    <div class="custom">
                    </div>
                    <div><a id="addemsFree" class="elementvisable">为指定地区城市设置运费</a></div>
                </div>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="ShippingWay" data-method="平邮" value="3" id="ckOrgMail">
                        平邮
                    </label>
                </div>
                <div class="mail" id="mail">
                    <div class="default">
                    </div>
                    <div class="custom">
                    </div>
                    <div><a id="addmaiFree" class="elementvisable">为指定地区城市设置运费</a></div>
                </div>
            </div>
        </div>

       
        <div class="form-group">
            <label class="checkbox-inline col-md-2 control-label">
                <input type="checkbox" id="ckcondition" />
                <strong>指定条件包邮</strong></label>
            <input type="hidden" name="freight" id="freight" />
            <input type="hidden" name="freeship" id="freeship" />
        </div>
        
         <div class="form-group">
             <label class="col-md-2 control-label"></label>
            <div class="col-md-8">
                <table class="table table-bordered" id="tb_condition">
                    <thead>
                        <tr>
                            <td colspan="4" class="elementvisable">选择地区</td>
                            <td>选择运送方式</td>
                            <td>选择快递</td>
                            <td>设置包邮条件</td>
                            <td>操作</td>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td colspan="3" class="elementvisable">未添加地区</td>
                            <td class="elementvisable"><a onclick="page.editArea(this,'condtionSelect')">编辑</a></td>
                            <td>
                                <select class="freeshiptransfer">
                                </select></td>
                            <td></td>
                            <td>
                                <select class="freeshipprice">
                                </select>
                                <p></p>
                                <div class="condition1"></div>
                                <div class="condition2" style="display: none;"></div>
                                <div class="condition3" style="display: none;">
                                </div>
                            </td>
                            <td>
                                <a class="front" href="#">+</a>  <a class="after" href="#">&times;</a>
                            </td>
                        </tr>
                    </tbody>
                </table>

            </div>
        </div>
        
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="submit" id="btlogistics" class="btn btn-default" value="保存并返回" />
            </div>
        </div>
    }


</div>


<div class="modal fade" id="expressSelect">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Express</h4>
            </div>
            <div class="modal-body">

                <input type="hidden" id="hdexpress" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button id="save" type="button" class="btn btn-primary">Save</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>



<div class="modal fade" id="emsSelect">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">EMS</h4>
            </div>
            <div class="modal-body">

                <input type="hidden" id="hdems" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button id="saveems" type="button" class="btn btn-primary">Save</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

<div class="modal fade" id="mailSelect">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Mail</h4>
            </div>
            <div class="modal-body">

                <input type="hidden" id="hdmail" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button id="savemail" type="button" class="btn btn-primary">Save</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>


<div class="modal fade" id="condtionSelect">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Mail</h4>
            </div>
            <div class="modal-body">

                <input type="hidden" id="hdcondtion" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button id="savecondtion" type="button" class="btn btn-primary">Save</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

